package com;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;

import java.nio.charset.Charset;
import java.util.Arrays;
import org.junit.Assert;

/**
 * @author clj
 * @date 2022/9/8
 * @desc AES加密测试main方法
 */
public class AesEncrypt {
    public static void main(String[] args) {
        AES aes = new AES(Mode.CBC, Padding.ZeroPadding,
                "bwsuart13iap2021".getBytes(), "iap2021bwsensinc".getBytes());
        System.out.println("bwsuart13iap2021.getBytes(): " + Arrays.toString("bwsuart13iap2021".getBytes()));
        System.out.println("iap2021bwsensinc.getBytes(): " + Arrays.toString("iap2021bwsensinc".getBytes()));
        System.out.println();
        String encryptStr = "qwertyui123456789";
        String encryptBase64 = aes.encryptBase64(encryptStr, Charset.forName("gb2312"));
        System.out.println("encryptedBase64Str: " + encryptBase64);
        Assert.assertEquals("KEY17MTBrc29SnyFP2CnHi3imJGbN27T5ucXjEckNxg=", encryptBase64);

        String decryptStr = aes.decryptStr(Base64.decode(encryptBase64));
        System.out.println("decryptedStr: " + decryptStr);
        Assert.assertEquals(encryptStr, decryptStr);
    }
}
